using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Travel.UserControls
{
    public partial class BookingList : UserControl
    {
        public BookingList()
        {
            InitializeComponent();
        }
        // The ListView Sorter
        private Travel.Library.ListViewItemComparer _lvwItemComparer = new Travel.Library.ListViewItemComparer();
        private BookingReport obj_BookingReport = null;
        private void lvBooking_DoubleClick(object sender, EventArgs e)
        {
            Booking objBooking = new Booking();
            objBooking.Show();
        }

        private void BookingList_Load(object sender, EventArgs e)
        {
            cmbFormat.SelectedIndex = 1;
            this.lvBooking.ListViewItemSorter = _lvwItemComparer;	
        }        

        private void cmbFormat_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbFormat.SelectedIndex == 0)
            {
                this.lvBooking.View = View.LargeIcon;
            }
            else
            {
                this.lvBooking.View = View.Details;
            }
        }

        private void lvBooking_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            // Determine if clicked column is already the column that is being sorted.
            if (e.Column == _lvwItemComparer.SortColumn)
            {
                // Reverse the current sort direction for this column.
                if (_lvwItemComparer.Order == SortOrder.Ascending)
                {
                    _lvwItemComparer.Order = SortOrder.Descending;
                }
                else
                {
                    _lvwItemComparer.Order = SortOrder.Ascending;
                }
            }
            else
            {
                // Set the column number that is to be sorted; default to ascending.
                _lvwItemComparer.SortColumn = e.Column;
                _lvwItemComparer.Order = SortOrder.Ascending;
            }

            // Perform the sort with these new sort options.
            this.lvBooking.Sort();
        }

        private void reportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (obj_BookingReport == null)
            {
                obj_BookingReport = new BookingReport();
            }
            obj_BookingReport.Show();
        }        
    }
}
